package com.wisdytech.linkdcs.equipLifeCycle.malfunction.action;


import com.wisdytech.common.handler.ResourceMatchingService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.model.MalfunctionDemo;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.IMalfunctionDemoService;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.IMalfunctionRecordService;
import com.wisdytech.linkdcs.equipStop.model.EquipStop;
import com.wisdytech.linkdcs.system.model.SysDict;
import com.wisdytech.linkdcs.system.model.SysUser;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenbin
 * @since 2018-07-24
 */
@Controller
@RequestMapping("/equipLifeCycle/malfunction/demo")
public class MalfunctionDemoAction {
	
	@Autowired
	private IMalfunctionDemoService iMalfunctionDemoService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    /**
    *
    * <p>Description: 设备信息</p>
    * @param model model
    * @return String
    */
   @RequestMapping("/index")
   public String equipmentIndex(Model model, HttpServletRequest httpRequest){
       this.resourceMatchingService.getResourceName(httpRequest,model);
       return "lifeCycle/equipLifeCycle/malfunction/demo";
   }

	@RequestMapping("/listMalfunctionReasonBySearch/get.mvc")
	@ResponseBody
	public StandardResult listMalfunctionReasonBySearch(String search) {
		List<SysDict> list = iMalfunctionDemoService.listMalfunctionReasonBySearch(search);
		return StandardResult.getSuccessResult(list);
					
	}
	
	
	   /**
	    * @param filter 分页参数
	    * @throws IOException 
	    */
	   @RequestMapping(value = "/listDemoByFilter/get.mvc")
	   @ResponseBody
	   public StandardTableResult<MalfunctionDemo> listDemoByFilter(String malfunctionType,String malfunctionTitle,Filter filter) throws IOException{
	   		PageInfo<MalfunctionDemo> equipStops =this.iMalfunctionDemoService.listDemoByFilter(malfunctionType,malfunctionTitle,filter);
	       return new StandardTableResult<MalfunctionDemo>(equipStops.getTotal(),equipStops.getList());
	   }
	
	   /**
	    * 保存
	    * @param property 属性对象
	    * @param session 
	    * @return 保存结果集
	    */
	   @RequestMapping(value = "/saveDemo/save.mvc")
	   @ResponseBody
	   public StandardResult saveDemo(MalfunctionDemo malfunctionDemo, HttpSession session) {
	       SysUser sysUser = BaseUtil.getCurrentUser();
	       String loginName = sysUser.getUsername();
	       if (StringUtils.isBlank(malfunctionDemo.getPkId())) {
	    	   iMalfunctionDemoService.addDemo(malfunctionDemo, loginName);
	       }else {
	    	   iMalfunctionDemoService.updateDemo(malfunctionDemo, loginName);
	       }
	       return  StandardResult.getSuccessResult();
	   }
	   
	   
	   /**
	    * 通过id获取
	    * @param id 主键id
	    */
	   @RequestMapping(value = "/getDemoById/get.mvc")
	   @ResponseBody
	   public StandardResult getDemoById(String pkId) {
		   MalfunctionDemo MalfunctionDemo = iMalfunctionDemoService.getDemoById(pkId);
	       return StandardResult.getSuccessResult(MalfunctionDemo);
	   }
	   
	   /**
	    * 通过id批量删除
	    * @param id 主键id
	    * @return 删除结果集
	    */
	   @RequestMapping(value = "/delDemoById/del.mvc")
	   @ResponseBody
	   public StandardResult delDemoById(String pkIds) {
		   iMalfunctionDemoService.delDemoById(pkIds);
	       return StandardResult.getSuccessResult();
	   }
	   
	   
	   /**
	    * 模糊查询
	    * @param id 主键id
	    */
	   @RequestMapping(value = "/selectDemoByTitle/get.mvc")
	   @ResponseBody
	   public StandardResult selectDemoByTitle(String search) {
		   List<MalfunctionDemo> list = iMalfunctionDemoService.selectDemoByTitle(search);
	       return StandardResult.getSuccessResult(list);
	   }
}

